package huoye.shops.huoye.operation.presenter;


import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.huoye.operation.model.SharePondData;
import huoye.shops.huoye.operation.model.ToUrl;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.IMineSetEventDetailsView;
import huoye.shops.huoye.operation.view.ISharePondView;


/**
 * Created by uesr on 2017/7/19.
 */

public class MineSetEventDetailsPresenter extends BasePresenter<IMineSetEventDetailsView> {


    private OperationService mService;

    //获取活动详情
    public void  getEventDetail(String eventId){
        mService.getEventDetail(eventId,new MineBaseJsonRequestCallback<SharePondData>(SharePondData.class) {

            @Override
            public void onSuccess(SharePondData sharePondData) {
                super.onSuccess(sharePondData);
                view.setEventData(sharePondData);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }






    //商家取消活动
    public void cancelEvent(String eventId){
        mService.cancelEvent(eventId,new MineBaseJsonRequestCallback<SharePondData>(SharePondData.class) {
            @Override
            public void onSuccess() {
                super.onSuccess();
                view.makeToast("取消活动成功");
                view.finish();
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


  //生成活动扫描二维码URL
    public void eventToUrl(String eventId){
        mService.eventToUrl(eventId,new MineBaseJsonRequestCallback<ToUrl>(ToUrl.class) {

            @Override
            public void onSuccess(ToUrl toUrl) {
                super.onSuccess(toUrl);
                view.getEventUrl(toUrl);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }



    @Override
    public void onStart() {
        mService = new OperationService();
    }
}
